//
//  EPMWelcomeViewController.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/26.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMWelcomeViewController.h"
#import "EPMUserAccountModelView.h"
//#import  <YYWebImage.h>

@interface EPMWelcomeViewController ()
    @property (weak,nonatomic) UIImageView* imgHead;
    @property (weak,nonatomic) UILabel* labWelcome;
@end
static  CGFloat iconH = 85;
@implementation EPMWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        [self startAnimation];
        
    }
    
#pragma
#pragma-设置动画
- (void)startAnimation{
    [_imgHead mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-[UIScreen mainScreen].bounds.size.height + 180 +iconH);
    }];
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{
        
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            _labWelcome.alpha = 1.0;
            
        } completion:^(BOOL finished) {
            //跳转页面
            [[NSNotificationCenter defaultCenter] postNotificationName:SWITCHROOTVIEWCONTROLLERNOTI object:@"welcomeVC"];
        }];
        
    }];
    
    
}
    
    
#pragma
#pragma-设置UI
    - (void)setupUI{
    
     UIImageView* imgHead = [[UIImageView alloc]init];
        _imgHead = imgHead;
      [ self.view addSubview:imgHead];
        
        UILabel* labWelcom = [UILabel EPM_Title:@"欢迎回来" textColor:[UIColor darkGrayColor] fontSize:15];
        labWelcom.textAlignment = NSTextAlignmentCenter;
        _labWelcome = labWelcom;
        [self.view addSubview:labWelcom];
        
        //设置约束
        [imgHead mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0);
            make.bottom.offset(-180);
            make.width.height.mas_equalTo(iconH);
        }];
        imgHead.layer.cornerRadius = iconH /2;
        imgHead.layer.masksToBounds = YES;
        ;
       
        [imgHead sd_setImageWithURL:[NSURL URLWithString:[EPMUserAccountModelView sheardTool].headURL] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        
        [labWelcom mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0);
            make.top.equalTo(imgHead.mas_bottom).offset(17);
        }];
        //在动画前隐藏
        labWelcom.alpha = 0;
    }

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
